<template>
  <div>
    <el-table :data="tableData" style="width: 100%" border>
      <el-table-column prop="name" label="统计指标" width="180"></el-table-column>
      <el-table-column prop="value" label="统计值" width="180"></el-table-column>
    </el-table>
  </div>
</template>

<script>
import axios from "axios";
import { getToken } from "@/utils/auth";
/* import { WAREHOUSES_PATH } from "../../../api/constants/constants.js"; */

export default {
  data() {
    return {
      tableData: [],
    };
  },
  created() {
    this.fetchData();
  },
  methods: {
    async fetchData() {
      try {
        const token = getToken();
        const response = await axios.get(
          `${process.env.VUE_APP_BASE_API}/wareHouses/RepairNumber`, {
         /*  params: {
            excelFilePath: encodeURIComponent(WAREHOUSES_PATH),
          }, */
          headers: {
            Authorization: `Bearer ${token}`,
          }
        });

        if (response.data) {
          const data = response.data;

          // 转换数据为表格格式
          this.tableData = [
            { name: "25%分位数", value: data["25th"] || 'N/A' },
            { name: "50%分位数", value: data["50th"] || 'N/A' },
            { name: "75%分位数", value: data["75th"] || 'N/A' },
            { name: "数量", value: data.count || 'N/A' },
            { name: "平均值", value: data.average || 'N/A' },
            { name: "最大值", value: data.max || 'N/A' },
            { name: "最小值", value: data.min || 'N/A' },
            { name: "标准差", value: data.standardDeviation || 'N/A' }
          ];

          // 按照名称排序
          this.tableData.sort((a, b) => a.name.localeCompare(b.name));

        } else {
          console.error("Invalid response format:", response);
          this.$message.error("数据格式错误");
        }
      } catch (error) {
        console.error("Error fetching data:", error);
        this.$message.error("获取数据失败");
      }
    }
  },
};
</script>

<style scoped>
.el-table {
  margin: 20px auto;
}
</style>
